Matt Hague adds support for OSM way center tags.
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 29 Sep 2014 21:49:05 +0000 (21:49 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 29 Sep 2014 21:49:05 +0000 (21:49 +0000)
gpsbabel/osm.cc
gpsbabel/reference/osm-center-data.gpx [new file with mode: 0644]
gpsbabel/reference/osm-center-data.xml [new file with mode: 0644]
gpsbabel/testo.d/osm.test

index 9db63fc14d0ca99b72ea24be343f270f776cc733..a580bd1f2aa17ba94b574fd0277c27ab2c930c20 100644 (file)
@@ -50,7 +50,7 @@ static route_head* rte;
 static Waypoint* wpt;
 
 static xg_callback     osm_node, osm_node_tag, osm_node_end;
-static xg_callback     osm_way, osm_way_nd, osm_way_tag, osm_way_end;
+static xg_callback     osm_way, osm_way_nd, osm_way_tag, osm_way_center, osm_way_end;
 
 static
 xg_tag_mapping osm_map[] = {
@@ -60,6 +60,7 @@ xg_tag_mapping osm_map[] = {
   { osm_way,   cb_start,       "/osm/way" },
   { osm_way_nd,        cb_start,       "/osm/way/nd" },
   { osm_way_tag,       cb_start,       "/osm/way/tag" },
+  { osm_way_center,    cb_start,       "/osm/way/center" },
   { osm_way_end,       cb_end,         "/osm/way" },
   { NULL,      (xg_cb_type)0,          NULL }
 };
@@ -579,6 +580,8 @@ static void
 osm_way(xg_string args, const QXmlStreamAttributes* attrv)
 {
   rte = route_head_alloc();
+  // create a wpt to represent the route center if it has a center tag
+  wpt = new Waypoint;
   if (attrv->hasAttribute("id")) {
     rte->rte_desc =  "osm-id " + attrv->value("id").toString();
   }
@@ -607,6 +610,7 @@ osm_way_tag(xg_string args, const QXmlStreamAttributes* attrv)
 {
   QString key, value;
   QString str;
+  signed char ikey;
 
   if (attrv->hasAttribute("k")) {
     key = attrv->value("k").toString();
@@ -620,9 +624,35 @@ osm_way_tag(xg_string args, const QXmlStreamAttributes* attrv)
   if (key == QLatin1String("name")) {
     if (rte->rte_name.isEmpty()) {
       rte->rte_name = str;
+      wpt->shortname = str;
     }
   } else if (key == QLatin1String("name:en")) {
     rte->rte_name = str;
+
+    wpt->shortname = str;
+   // The remaining cases only apply to the center node
+  } else if ((ikey = osm_feature_ikey(key)) >= 0) {
+    wpt->icon_descr = osm_feature_symbol(ikey, CSTR(value));
+  } else if (key == "note") {
+    if (wpt->notes.isEmpty()) {
+      wpt->notes = str;
+    } else {
+      wpt->notes += "; ";
+      wpt->notes += str;
+    }
+  }
+}
+
+static void
+osm_way_center(xg_string args, const QXmlStreamAttributes* attrv)
+{
+  wpt->wpt_flags.fmt_use = 1;
+
+  if (attrv->hasAttribute("lat")) {
+    wpt->latitude = attrv->value("lat").toString().toDouble();
+  }
+  if (attrv->hasAttribute("lon")) {
+    wpt->longitude = attrv->value("lon").toString().toDouble();
   }
 }
 
@@ -633,6 +663,14 @@ osm_way_end(xg_string args, const QXmlStreamAttributes*)
     route_add_head(rte);
     rte = NULL;
   }
+
+  if (wpt) {
+    if (wpt->wpt_flags.fmt_use) {
+      waypt_add(wpt);
+    } else {
+      wpt = NULL;
+    }
+  }
 }
 
 static void
diff --git a/gpsbabel/reference/osm-center-data.gpx b/gpsbabel/reference/osm-center-data.gpx
new file mode 100644 (file)
index 0000000..4a07f49
--- /dev/null
@@ -0,0 +1,199 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gpx version="1.0" creator="GPSBabel - http://www.gpsbabel.org" xmlns="http://www.topografix.com/GPX/1/0">
+  <time>1970-01-01T00:00:00Z</time>
+  <bounds minlat="50.600000000" minlon="-0.400000000" maxlat="51.100000000" maxlon="0.100000000"/>
+  <wpt lat="50.900000000" lon="0.100000000">
+    <name>osm-id 1</name>
+    <cmt>osm-id 1</cmt>
+    <desc>osm-id 1</desc>
+  </wpt>
+  <wpt lat="50.900000000" lon="-0.100000000">
+    <name>osm-id 2</name>
+    <cmt>osm-id 2</cmt>
+    <desc>osm-id 2</desc>
+  </wpt>
+  <wpt lat="51.100000000" lon="-0.100000000">
+    <name>osm-id 3</name>
+    <cmt>osm-id 3</cmt>
+    <desc>osm-id 3</desc>
+  </wpt>
+  <wpt lat="51.100000000" lon="0.100000000">
+    <name>osm-id 4</name>
+    <cmt>osm-id 4</cmt>
+    <desc>osm-id 4</desc>
+  </wpt>
+  <wpt lat="50.800000000" lon="0.000000000">
+    <name>osm-id 5</name>
+    <cmt>osm-id 5</cmt>
+    <desc>osm-id 5</desc>
+  </wpt>
+  <wpt lat="50.800000000" lon="-0.200000000">
+    <name>osm-id 6</name>
+    <cmt>osm-id 6</cmt>
+    <desc>osm-id 6</desc>
+  </wpt>
+  <wpt lat="51.000000000" lon="-0.200000000">
+    <name>osm-id 7</name>
+    <cmt>osm-id 7</cmt>
+    <desc>osm-id 7</desc>
+  </wpt>
+  <wpt lat="51.000000000" lon="0.000000000">
+    <name>osm-id 8</name>
+    <cmt>osm-id 8</cmt>
+    <desc>osm-id 8</desc>
+  </wpt>
+  <wpt lat="50.700000000" lon="-0.100000000">
+    <name>osm-id 9</name>
+    <cmt>osm-id 9</cmt>
+    <desc>osm-id 9</desc>
+  </wpt>
+  <wpt lat="50.700000000" lon="-0.300000000">
+    <name>osm-id 10</name>
+    <cmt>osm-id 10</cmt>
+    <desc>osm-id 10</desc>
+  </wpt>
+  <wpt lat="50.900000000" lon="-0.300000000">
+    <name>osm-id 11</name>
+    <cmt>osm-id 11</cmt>
+    <desc>osm-id 11</desc>
+  </wpt>
+  <wpt lat="50.900000000" lon="-0.100000000">
+    <name>osm-id 12</name>
+    <cmt>osm-id 12</cmt>
+    <desc>osm-id 12</desc>
+  </wpt>
+  <wpt lat="50.600000000" lon="-0.200000000">
+    <name>osm-id 13</name>
+    <cmt>osm-id 13</cmt>
+    <desc>osm-id 13</desc>
+  </wpt>
+  <wpt lat="50.600000000" lon="-0.400000000">
+    <name>osm-id 14</name>
+    <cmt>osm-id 14</cmt>
+    <desc>osm-id 14</desc>
+  </wpt>
+  <wpt lat="50.800000000" lon="-0.400000000">
+    <name>osm-id 15</name>
+    <cmt>osm-id 15</cmt>
+    <desc>osm-id 15</desc>
+  </wpt>
+  <wpt lat="50.800000000" lon="-0.200000000">
+    <name>osm-id 16</name>
+    <cmt>osm-id 16</cmt>
+    <desc>osm-id 16</desc>
+  </wpt>
+  <wpt lat="51.000000000" lon="0.000000000">
+    <name>My Restuarant</name>
+    <cmt>My Restuarant</cmt>
+    <desc>My Restuarant</desc>
+    <sym>Restaurant</sym>
+  </wpt>
+  <wpt lat="50.800000000" lon="-0.200000000">
+    <name>My Pub</name>
+    <cmt>My Local Pub</cmt>
+    <desc>My Local Pub</desc>
+    <sym>Bar</sym>
+  </wpt>
+  <wpt lat="50.700000000" lon="-0.300000000">
+    <name>My Store</name>
+    <cmt>My Local Store; Sells Food</cmt>
+    <desc>My Local Store; Sells Food</desc>
+    <sym>Convenience Store</sym>
+  </wpt>
+  <rte>
+    <name>My Restuarant</name>
+    <desc>osm-id 1</desc>
+    <rtept lat="50.900000000" lon="0.100000000">
+      <name>osm-id 1</name>
+      <cmt>osm-id 1</cmt>
+      <desc>osm-id 1</desc>
+    </rtept>
+    <rtept lat="50.900000000" lon="-0.100000000">
+      <name>osm-id 2</name>
+      <cmt>osm-id 2</cmt>
+      <desc>osm-id 2</desc>
+    </rtept>
+    <rtept lat="51.100000000" lon="-0.100000000">
+      <name>osm-id 3</name>
+      <cmt>osm-id 3</cmt>
+      <desc>osm-id 3</desc>
+    </rtept>
+    <rtept lat="51.100000000" lon="0.100000000">
+      <name>osm-id 4</name>
+      <cmt>osm-id 4</cmt>
+      <desc>osm-id 4</desc>
+    </rtept>
+  </rte>
+  <rte>
+    <name>My Pub</name>
+    <desc>osm-id 2</desc>
+    <rtept lat="50.800000000" lon="0.000000000">
+      <name>osm-id 5</name>
+      <cmt>osm-id 5</cmt>
+      <desc>osm-id 5</desc>
+    </rtept>
+    <rtept lat="50.800000000" lon="-0.200000000">
+      <name>osm-id 6</name>
+      <cmt>osm-id 6</cmt>
+      <desc>osm-id 6</desc>
+    </rtept>
+    <rtept lat="51.000000000" lon="-0.200000000">
+      <name>osm-id 7</name>
+      <cmt>osm-id 7</cmt>
+      <desc>osm-id 7</desc>
+    </rtept>
+    <rtept lat="51.000000000" lon="0.000000000">
+      <name>osm-id 8</name>
+      <cmt>osm-id 8</cmt>
+      <desc>osm-id 8</desc>
+    </rtept>
+  </rte>
+  <rte>
+    <name>My Pub</name>
+    <desc>osm-id 3</desc>
+    <rtept lat="50.700000000" lon="-0.100000000">
+      <name>osm-id 9</name>
+      <cmt>osm-id 9</cmt>
+      <desc>osm-id 9</desc>
+    </rtept>
+    <rtept lat="50.700000000" lon="-0.300000000">
+      <name>osm-id 10</name>
+      <cmt>osm-id 10</cmt>
+      <desc>osm-id 10</desc>
+    </rtept>
+    <rtept lat="50.900000000" lon="-0.300000000">
+      <name>osm-id 11</name>
+      <cmt>osm-id 11</cmt>
+      <desc>osm-id 11</desc>
+    </rtept>
+    <rtept lat="50.900000000" lon="-0.100000000">
+      <name>osm-id 12</name>
+      <cmt>osm-id 12</cmt>
+      <desc>osm-id 12</desc>
+    </rtept>
+  </rte>
+  <rte>
+    <name>My Store</name>
+    <desc>osm-id 3</desc>
+    <rtept lat="50.600000000" lon="-0.200000000">
+      <name>osm-id 13</name>
+      <cmt>osm-id 13</cmt>
+      <desc>osm-id 13</desc>
+    </rtept>
+    <rtept lat="50.600000000" lon="-0.400000000">
+      <name>osm-id 14</name>
+      <cmt>osm-id 14</cmt>
+      <desc>osm-id 14</desc>
+    </rtept>
+    <rtept lat="50.800000000" lon="-0.400000000">
+      <name>osm-id 15</name>
+      <cmt>osm-id 15</cmt>
+      <desc>osm-id 15</desc>
+    </rtept>
+    <rtept lat="50.800000000" lon="-0.200000000">
+      <name>osm-id 16</name>
+      <cmt>osm-id 16</cmt>
+      <desc>osm-id 16</desc>
+    </rtept>
+  </rte>
+</gpx>
diff --git a/gpsbabel/reference/osm-center-data.xml b/gpsbabel/reference/osm-center-data.xml
new file mode 100644 (file)
index 0000000..43d90a7
--- /dev/null
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<osm version="0.6" generator="Handmade Test">
+  <node id="1" lat="50.9" lon="0.1"/>
+  <node id="2" lat="50.9" lon="-0.1"/>
+  <node id="3" lat="51.1" lon="-0.1"/>
+  <node id="4" lat="51.1" lon="0.1"/>
+  <node id="5" lat="50.8" lon="0"/>
+  <node id="6" lat="50.8" lon="-0.2"/>
+  <node id="7" lat="51" lon="-0.2"/>
+  <node id="8" lat="51" lon="0"/>
+  <node id="9" lat="50.7" lon="-0.1"/>
+  <node id="10" lat="50.7" lon="-0.3"/>
+  <node id="11" lat="50.9" lon="-0.3"/>
+  <node id="12" lat="50.9" lon="-0.1"/>
+  <node id="13" lat="50.6" lon="-0.2"/>
+  <node id="14" lat="50.6" lon="-0.4"/>
+  <node id="15" lat="50.8" lon="-0.4"/>
+  <node id="16" lat="50.8" lon="-0.2"/>
+
+  <way id="1">
+    <center lat="51" lon="0"/>
+    <nd ref="1"/>
+    <nd ref="2"/>
+    <nd ref="3"/>
+    <nd ref="4"/>
+    <tag k="addr:city" v="My Town"/>
+    <tag k="addr:housenumber" v="1"/>
+    <tag k="addr:street" v="My Street"/>
+    <tag k="building" v="yes"/>
+    <tag k="amenity" v="restaurant"/>
+    <tag k="name" v="My Restuarant"/>
+  </way>
+
+  <way id="2">
+    <nd ref="5"/>
+    <nd ref="6"/>
+    <nd ref="7"/>
+    <nd ref="8"/>
+    <tag k="addr:city" v="My Town"/>
+    <tag k="addr:housenumber" v="2"/>
+    <tag k="addr:street" v="My Street"/>
+    <tag k="building" v="yes"/>
+    <tag k="amenity" v="pub"/>
+    <tag k="name" v="My Pub"/>
+  </way>
+
+  <way id="3">
+    <nd ref="9"/>
+    <nd ref="10"/>
+    <nd ref="11"/>
+    <nd ref="12"/>
+    <center lat="50.8" lon="-0.2"/>
+    <tag k="addr:city" v="My Town"/>
+    <tag k="addr:housenumber" v="3"/>
+    <tag k="addr:street" v="My Street"/>
+    <tag k="building" v="yes"/>
+    <tag k="amenity" v="pub"/>
+    <tag k="name" v="My Pub"/>
+    <tag k="note" v="My Local Pub"/>
+  </way>
+
+  <way id="3">
+    <center lat="50.7" lon="-0.3"/>
+    <nd ref="13"/>
+    <nd ref="14"/>
+    <nd ref="15"/>
+    <nd ref="16"/>
+    <tag k="addr:city" v="My Town"/>
+    <tag k="addr:housenumber" v="4"/>
+    <tag k="addr:street" v="My Street"/>
+    <tag k="shop" v="convenience"/>
+    <tag k="name" v="My Store"/>
+    <tag k="note" v="My Local Store"/>
+    <tag k="note" v="Sells Food"/>
+  </way>
+
+</osm>
index d9a76d17c3c57d2950d9a9bbfd7ef37f8c6551f9..d2cab0fa12b93cf1c7b8e5ace7b6a37fd623c1fa 100644 (file)
@@ -4,5 +4,8 @@ rm -f ${TMPDIR}/osm-*
 gpsbabel -i osm -f ${REFERENCE}/osm-data.xml -o gpx -F ${TMPDIR}/osm-data.gpx  -o osm -F ${TMPDIR}/osm-out.xml
 compare ${REFERENCE}/osm-data.gpx ${TMPDIR}/osm-data.gpx 
 
+gpsbabel -i osm -f ${REFERENCE}/osm-center-data.xml -o gpx -F ${TMPDIR}/osm-center-data.gpx  -o osm -F ${TMPDIR}/osm-center-out.xml
+compare ${REFERENCE}/osm-center-data.gpx ${TMPDIR}/osm-center-data.gpx 
+
 # FIXME: implement a test for OSM writer, if possible.
 # compare ${REFERENCE}/osm-data.xml ${TMPDIR}/osm-out.xml